<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Message
 *
 * @author QuangKhoi
 */
class Message {
    
    /**
     *
     * @var Int
     */
    public $messageId;

    /**
     *
     * @var String
     */
    public $threadTitle;

    /**
     * @var String
     */
    public $lead;

    /**
     * @var String
     */
    public $text;

    /**
     * @var String
     */
    public $source;

    /**
     * @var String
     */
    public $url;

    /**
     * @var String
     */
    public $author;

    /**
     * @var String
     */
    public $postTitle;

    /**
     * @var DateTime
     */
    public $time;

    /**
     * @var Int
     */
    public $authorId;

    /**
     * @var Int
     */
    public $threadId;

    /**
     * @var Int
     */
    public $SMT;

    public function __construct() {
        
    }

    /**
     * Create new Message object store all data
     * @param int $messageId
     * @param string $threadTitle
     * @param string $lead
     * @param string $text
     * @param string $source
     * @param string $url
     * @param string $author
     * @param string $postTitle
     * @param DateTime $time
     * @param Int $authorId
     * @param Int $threadId
     * @param Int $SMT
     */
    public static function withData($messageId, $threadTitle, $lead, $text, $source, $url, $author, $postTitle, $time, $authorId, $threadId, $SMT) {
        /**
         * Assign data
         */
        $this->messageId = $messageId;
        $this->threadTitle = $threadTitle;
        $this->lead = $lead;
        $this->text = $text;
        $this->source = $source;
        $this->url = $url;
        $this->author = $author;
        $this->postTitle = $postTitle;
        $this->time = $time;
        $this->authorId = $authorId;
        $this->threadId = $threadId;
        $this->SMT = $SMT;
    }

    /**
     * Get message from server with specified id
     * @param array $messageId
     */
    public static function withId($messageId) {
        $reader = new ZPostReader($messageId, 7);
        $messages = array();
        try {
            $reader->read(function($item, $total) use (&$messages) {
                $messages[] = $item;
            });
            if (count($messages) > 1)
                return $messages;
            if (count($messages) == 1)
                return $messages[0];
        } catch (Exception $e) {
            //echo $e->getMessage();
        }
    }

    public function Save() {
        
    }

}

?>
